package edu.nf.ch05.service;

import edu.nf.ch05.entity.User;
import edu.nf.ch05.mapper.UserMapper;
import edu.nf.ch05.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * @author CSY
 * @date 2025 - 04 - 23
 */
public class UserService {
    public List<User> listUser(Map<String, Object> map) {
        try(SqlSession sqlSession = MybatisUtils.getSqlSession()){
            return sqlSession.getMapper(UserMapper.class)
                    .listUser(map);
        }
    }

    public List<User> listUsersById(List<Integer> ids) {
        try(SqlSession sqlSession = MybatisUtils.getSqlSession()){
            return sqlSession.getMapper(UserMapper.class)
                    .listUsersById(ids);
        }
    }

    public void update(User user){
        try(SqlSession sqlSession = MybatisUtils.getSqlSession()){
            sqlSession.getMapper(UserMapper.class).update(user);
        }
    }
}
